Skip to content

Allow LogBox and RedBox overlay dismissal via Android back button#56405

Closed
Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Abbondanzo:export-D100081099
Closed

Allow LogBox and RedBox overlay dismissal via Android back button#56405
Abbondanzo wants to merge 1 commit intofacebook:mainfrom
Abbondanzo:export-D100081099

Conversation

@Abbondanzo
Copy link
Copy Markdown
Contributor

Summary:
On Android, pressing the hardware back button while the LogBox inspector is open does nothing. LogBoxDialog is explicitly set to setCancelable(false) and there's no onBackPressed() override, so the back button is completely swallowed. The only way to close the inspector is the on-screen Minimize/Dismiss buttons.

For RedBox, the dialog is cancelable by default so back press does dismiss it visually, but it bypasses hideRedboxDialog(). The dialog reference and content view don't get cleaned up, leaving stale state.

This adds proper back button handling for both:

LogBox: LogBoxDialog now takes an onRequestClose callback and overrides onBackPressed() to invoke it. The surface delegate passes a callback that emits hardwareBackPress to the JS runtime, where a new BackHandler listener in LogBoxInspector calls onMinimize(). This keeps setCancelable(false) in place (so tapping outside the dialog doesn't dismiss it) while still running the full dismiss flow through JS: state reset, NativeLogBox.hide(), dialog cleanup.

RedBox: The anonymous Dialog subclass now overrides onBackPressed() to call hideRedboxDialog() directly, which dismisses the dialog, destroys the content view, and nulls the reference.

Changelog: [Internal] - Allow LogBox and RedBox overlays to respond to Android back button press

Differential Revision: D100081099

Summary:
On Android, pressing the hardware back button while the LogBox inspector is open does nothing. `LogBoxDialog` is explicitly set to `setCancelable(false)` and there's no `onBackPressed()` override, so the back button is completely swallowed. The only way to close the inspector is the on-screen Minimize/Dismiss buttons.

For RedBox, the dialog is cancelable by default so back press does dismiss it visually, but it bypasses `hideRedboxDialog()`. The dialog reference and content view don't get cleaned up, leaving stale state.

This adds proper back button handling for both:

**LogBox**: `LogBoxDialog` now takes an `onRequestClose` callback and overrides `onBackPressed()` to invoke it. The surface delegate passes a callback that emits `hardwareBackPress` to the JS runtime, where a new `BackHandler` listener in `LogBoxInspector` calls `onMinimize()`. This keeps `setCancelable(false)` in place (so tapping outside the dialog doesn't dismiss it) while still running the full dismiss flow through JS: state reset, `NativeLogBox.hide()`, dialog cleanup.

**RedBox**: The anonymous `Dialog` subclass now overrides `onBackPressed()` to call `hideRedboxDialog()` directly, which dismisses the dialog, destroys the content view, and nulls the reference.

Changelog: [Internal] - Allow LogBox and RedBox overlays to respond to Android back button press

Differential Revision: D100081099
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 9, 2026
@facebook-github-tools facebook-github-tools bot added p: Facebook Partner: Facebook Partner labels Apr 9, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 9, 2026

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100081099.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Abbondanzo in 8629a34

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 10, 2026
@Abbondanzo Abbondanzo deleted the export-D100081099 branch April 10, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants